package com.vint.leetcode;

import sun.security.krb5.internal.crypto.Aes128;

/*
 * 1. done
 * 2.   hard
 * 3.
 */
public class Leetcode97 {
    public boolean isInterleave(String s1, String s2, String s3) {
    	if(null==s1&&null==s2) return null==s3;
    	if(null==s1)return s2.equals(s3);
	    if(null==s2)return s1.equals(s3);
	    return help(s1,s1.length(),s2,s2.length(),s3,s3.length());
    }
    public boolean help(String s1, int s1l, String s2, int s2l, String s3, int s3l){
    	if(s1l==0){

	    }
    	if(s1.indexOf(s1l-1) == s3.indexOf(s3l -1)&&help(s1, s1l - 1, s2, s2l, s3, s3l - 1)) {
		    return true;
	    }else{
		    if(s2.indexOf(s2l-1) == s3.indexOf(s3l -1)&&help(s1, s1l , s2, s2l -1, s3, s3l - 1)) {
		    	return true;
		    }
	    }
	    return false;
  }
  public static void main(String[] args) {
      String s1 = "aabc";
	  String s2 = "dbbca";
	  String s3 = "aadbbcbcac";
	  Leetcode97 leetcode97 = new Leetcode97();
	  System.out.println(leetcode97.isInterleave(s1, s2, s3));
  }
}
